﻿<%@ include file="/WEB-INF/controllers/configuration/includes.jsp" %>


<style type="text/css">

	.nyroModalCont .botones{
	   	margin-right: 85px;
    	margin-top: 20px;
    	padding-bottom: 0;
    	width: 95%;
    	text-align:center;
    }
    
    .errores{
    	color: red;
    	padding: 5px;
    }
    
</style>

<form id="formulario22" action="formCambiarClave.do" method="post">

	<div id="contenedorErrores" class="errores" style="display: none;">		
	</div>
		
	<div style="padding-top:38px" class="formAux">	
		<div class="groupline">		
			<div class="line">
				<label><spring:message code="label.model.user.password" />:</label> 
				<input id="password" type="password"/>
				<input id="passwordHidden" type="hidden" name="passwordHidden"/>			
			</div>
			<div class="line">
				<label><spring:message code="label.model.user.repeatPassword" />:</label> 
				<input id="repeatPassword" type="password"/>	
				<input id="repeatPasswordHidden" type="hidden" name="repeatPasswordHidden"/>
			</div>			
			<div class="line botones">
				<input type="button" id="saveButton" class="baseBotton" onclick="aceptar();" value="<spring:message code="label.button.guardar" />"/>
				<input type="button" id="cancelButton" class="baseBotton cancelar" onclick="cerrarPopUp(null);" value="<spring:message code="label.button.cancelar" />"/>				
			</div>				
		</div>
	</div>
</form>
<div id="divLoadingForm" style="text-align: center; display:none">
	<img src="<c:url value="/img/loading.gif"/>" />
</div>	

<script type="text/javascript">
	
$(document).ready(function() {	
	var formOptions = {			
		 	error: error,
		 	success: cerrarPopUp, 			 				 
		 	dataType: "json"		 
		};		
	$("#formulario22").ajaxForm(formOptions);
	//Asignacion de evento para tecla INTRO en form
	$('#repeatPassword').bind("keypress", function(e){			
		if(e.which == 13){
			$("#saveButton").click();
		}			
	});
	$('.nyroModalBg').bind("click", function(e){
		$("#cancelButton").click();
	});
});
	
	
	function cerrarPopUp(json){
		
		if(json != undefined){	
			if(json.errores != null && json.errores.length > 0){
				$("#contenedorErrores").html(json.errores[0]);
				$(".formAux").css("padding-top","15px");
				$("#contenedorErrores").show();		
				$('#divLoadingForm').hide();
				$('#formulario22').show();
			}else{		
				$("#ocultoPassword").val($("#password").val());
				$("#ocultorepeatPassword").val($("#repeatPassword").val());
				$.nmTop().close();
			}
		}else{
			$.nmTop().close();
		}
	}
	
	function error(XMLHttpRequest, textStatus, errorThrown){
		var errorObject = JSON.parse(XMLHttpRequest.responseText);				
		if(errorObject != undefined 
				&&  errorObject.fielderrors != undefined 
				&& errorObject.fielderrors.errores != undefined)
			alert(errorObject.fielderrors.errores);						
	} 
	
	function aceptar(){
		if($('#password').val() != '' && $('#repeatPassword').val() != ''){
			$('#passwordHidden').val(hex_sha1($('#password').val()));
// 			$('#password').val("");
			$('#repeatPasswordHidden').val(hex_sha1($('#repeatPassword').val()));
// 			$('#repeatPassword').val("");
		}
		$('#formulario22').hide();
		$('#divLoadingForm').show();
		codificar = true;
		$("#contenedorErrores").hide();
		$("#formulario22").submit();
	}

</script>